package com.zsf.servlet;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.zsf.pojo.Product;
import com.zsf.pojo.Tag;
import com.zsf.service.ProductService;
import com.zsf.service.TagService;
import com.zsf.serviceImp.ProductServiceImp;
import com.zsf.serviceImp.TagServiceImp;

/**
 * Servlet implementation class AddProductServlet
 */
	@WebServlet("/addProduct")
public class AddProductServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
	ProductService productService=new ProductServiceImp();
	Product product=new Product();
	Tag tag=new Tag();
       

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		request.setCharacterEncoding("utf-8");
		product.setCode(request.getParameter("code"));
		product.setNote(request.getParameter("note"));
		product.setImgPath(request.getParameter("imgPath"));
		product.setTitle(request.getParameter("title"));
		tag.setId(Integer.valueOf(request.getParameter("tag")));
		product.setTag(tag);
		product.setTotalNum(Integer.valueOf(request.getParameter("totalNum")));
		product.setPrice(Double.valueOf(request.getParameter("price")));
		productService.insertProduct(product);
		response.sendRedirect("product");
	}

}
